# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=mpg123
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.26.1
pkgrel=1
pkgdesc="A console based real time MPEG Audio Player for Layer 1, 2 and 3 (mingw-w64)"
arch=('any')
url="https://www.mpg123.com/"
license=("LGPL2.1")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-openal"
             "${MINGW_PACKAGE_PREFIX}-portaudio"
             "${MINGW_PACKAGE_PREFIX}-SDL")
depends=("${MINGW_PACKAGE_PREFIX}-libtool"
         "${MINGW_PACKAGE_PREFIX}-gcc-libs")
optdepends=("${MINGW_PACKAGE_PREFIX}-openal"
            "${MINGW_PACKAGE_PREFIX}-portaudio"
            "${MINGW_PACKAGE_PREFIX}-SDL")
options=('strip' 'staticlibs' 'libtool')
source=("https://www.mpg123.com/download/mpg123-${pkgver}.tar.bz2"{,.sig})
sha256sums=('74d6629ab7f3dd9a588b0931528ba7ecfa989a2cad6bf53ffeef9de31b0fe032'
            'SKIP')
validpgpkeys=('D021FF8ECF4BE09719D61A27231C4CBC60D5CAFE')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  autoreconf -fi
}

build() {
  export lt_cv_deplibs_check_method='pass_all'
  [[ -d "build-${MINGW_CHOST}" ]] && rm -rf "build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
